package com.qyhl.webtv.commonlib.utils.push;

import android.util.Log;

import com.alibaba.sdk.android.push.CloudPushService;
import com.alibaba.sdk.android.push.CommonCallback;
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;

/**
 * Created by qyhl2 on 2017/12/15.
 */

public class PushTools {

    /**
     * 绑定账号
     */
    public static void BindAccount(String number) {
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        pushService.bindAccount(number, new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.e("BindTag", "绑定账号成功");
            }

            @Override
            public void onFailed(String s, String s1) {
                Log.e("BindTag", "绑定账号失败");
            }
        });
    }

    /**
     * 解除绑定账号
     */
    public static void unBindAccount() {
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        if( pushService!=null ){
            pushService.unbindAccount(new CommonCallback() {
                @Override
                public void onSuccess(String s) {
                    Log.e("BindTag", "解绑设备成功");
                }

                @Override
                public void onFailed(String s, String s1) {
                    Log.e("BindTag", "解绑设备失败");
                }
            });
        }
    }

    /**
     * 绑定推送tag
     */
    public static void BindTag(final String tag) {
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        String[] strs = {tag};
        pushService.bindTag(CloudPushService.DEVICE_TARGET, strs, null, new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.e("BindTag", "绑定Tag成功" + tag);
            }

            @Override
            public void onFailed(String s, String s1) {
                Log.e("BindTag", "绑定Tag失败");
            }
        });
    }

    /**
     * 绑定TAG到设备
     *
     * @param tag
     */
    public static void BindTagByDevice(final String tag) {
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        String[] strs = {tag};
        pushService.bindTag(CloudPushService.DEVICE_TARGET, strs, "", new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.e("BindTag", "绑定设备Tag成功" + tag);
            }

            @Override
            public void onFailed(String s, String s1) {
                Log.e("BindTag", "绑定Tag失败");
            }
        });
    }

    /**
     * 解除设备绑定的TAG
     *
     * @param tag
     */
    public static void unBindTagByDevice(String tag) {
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        String[] strs = {tag};
        pushService.unbindTag(CloudPushService.DEVICE_TARGET, strs, "", new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.e("BindTag", "解绑设备Tag成功");
            }

            @Override
            public void onFailed(String s, String s1) {
                Log.e("BindTag", "解绑设备Tag失败");
            }
        });
    }


    /**
     * 检查账号Tag
     */
    public static  void checkTag(){
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        pushService.listTags(CloudPushService.ACCOUNT_TARGET, new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.e("BindTag","****"+s);
            }

            @Override
            public void onFailed(String s, String s1) {

            }
        });
    }

    /**
     * 解除绑定
     *
     * @param tag
     */
    public static void unBindTag(String tag) {
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        String[] strs = {tag};
        pushService.unbindTag(CloudPushService.DEVICE_TARGET, strs, null, new CommonCallback() {
            @Override
            public void onSuccess(String s) {
                Log.e("BindTag", "解绑账号Tag成功");
            }

            @Override
            public void onFailed(String s, String s1) {
                Log.e("BindTag", "解绑账号Tag失败");
            }
        });
    }




}
